package lib.quasar.widget.image;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;

/**
 * description: 角标
 * created by kalu on 2018/4/2 14:02
 */
public class AngleImageView extends AppCompatImageView {

    private final Paint mPaint = new Paint();

    public AngleImageView(Context context) {
        super(context);
    }

    public AngleImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public AngleImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /************************************************************/

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        // 1.画角标背景
        mPaint.setColor(Color.RED);
        Path path3 = new Path();
        path3.moveTo(0, 0);
        path3.lineTo(getWidth() / 2, 0);
        path3.lineTo(0, getHeight() / 2);
        path3.close();
        canvas.drawPath(path3, mPaint);
        // 2.画角标文字
        canvas.translate(0, 0);
        canvas.rotate(-45, this.getWidth() / 2f, this.getHeight() / 2f);
        canvas.drawText("第三个世界各地", getWidth() / 2, getHeight(), mPaint);
    }
}
